package com.gome.bg.dwr;

import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.stereotype.Service;
import com.gome.bg.util.DwrContextUtil;
import com.gome.bg.util.rbToATG.RefundAuditResult;
import com.gome.bg.util.rbToATG.RefundAuditResultReply;
import com.gome.util.TraceInfo;


@Service
@RemoteProxy
public class DwrService {
	
	@RemoteMethod
	public void testdwr(String str) {
		TraceInfo.traceInfo(str); 
	}

	DwrContextUtil dc = DwrContextUtil.getInstance();

	@RemoteMethod
	public String getInfo(Map map) {
		TraceInfo.traceInfo(); 
		Iterator iter = map.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			Object key = entry.getKey();
			Object val = entry.getValue();
			TraceInfo.traceInfo(key);
			TraceInfo.traceInfo(val);
		}
		
		
		String errdesc = null;
		String rstate = (String)map.get("refundState");
		if(rstate.equals("S")){
			errdesc="退款成功";
		}else{
			errdesc="退款失败";
		}
		TraceInfo.traceInfo((String)map.get("refundService"));
		String str = (String)map.get("refundService");
		TraceInfo.traceInfo(dc.getUrl((String)map.get("refundService")));
		java.util.Calendar c = java.util.Calendar.getInstance();
		c.setTime(new Date());
		RefundAuditResult refundState=new RefundAuditResult();
		refundState.setErrorDesc("退款成功"); 
		refundState.setRefundNo((String)map.get("refundNo")); 
		refundState.setRefundFinishTime(dc.convert(c));
		refundState.setState(rstate);
		refundState.setRefundType("A");
		if(((String)map.get("banktype")).equals("11")||((String)map.get("banktype")).equals("27")||((String)map.get("banktype")).equals("21")){
			if(((String)map.get("refundDetailsId"))==null){
				refundState.setRefundTransId((String)map.get("refundNo"));
			}else{
				refundState.setRefundTransId((String)map.get("refundNo")+"A"+(String)map.get("refundDetailsId"));
			}
		}
		//refundState.setRefundTransId("");
		refundState.setRefundDetailsId((String)map.get("refundDetailsId"));
		String url = dc.getUrl((String)map.get("refundService"));
		System.out.println(url);
		RefundAuditResultReply rr=	dc.isCallAtGSuccess(refundState,url);
		System.out.println("ok==="+rr.getState());
		return rr.getState();
	}

	
	
	

}
